package com.chunguang.netty.comon;

import org.springframework.beans.BeanUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import com.chunguang.netty.domain.RequestData;
import com.chunguang.netty.domain.TransferData;
import com.chunguang.netty.listener.ApplicationFactory;
import com.chunguang.netty.service.RequestDataService;

import io.netty.channel.ChannelFuture;

public class Main {

	public static void main(String[] args) {
		try {
			ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext( new String[] { "spring-context.xml" });
			context.start();
			Client c = Client.getInstance();
			ChannelFuture cf = c.getChannelFuture();
			
			ApplicationContext context1 = ApplicationFactory.getContext();
			System.out.println("dddddddd");
			RequestDataService service = (RequestDataService) context1.getBean("requestDataService");
			TransferData transferData = new TransferData();
			transferData.setCheckNumber("aaaaaaaaaaaaaaaaaa");
			transferData.setSync(0);
			service.insert(transferData );
			RequestData requestData2 = new RequestData();
			BeanUtils.copyProperties(transferData, requestData2, new String[]{"sync"});
			cf.channel().writeAndFlush(requestData2);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
